package com.lsx143.wordcount.day2;

import org.apache.flink.api.common.functions.RichMapFunction;
import org.apache.flink.configuration.Configuration;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;

import java.util.Arrays;

public class RichFunction {
    public static void main(String[] args) {
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
        env.setParallelism(3);
        DataStreamSource<String> dss1 = env.fromCollection(Arrays.asList("Json", "Tom", "Perter", "Jerry"));
        dss1.map(new RichMapFunction<String, String>() {
            @Override
            public String map(String s) throws Exception {
                return s;
            }

            @Override
            public void open(Configuration parameters) throws Exception {
                System.out.println("opening");
            }

            @Override
            public void close() throws Exception {
                System.out.println("closing");
            }


        }).print();
        try {
            env.execute();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
